import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

@WebServlet("/upload")
public class Upload extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 输入流
        InputStream bi = req.getInputStream();

        //输出流
        String path = req.getServletContext().getRealPath("file\\upload.png");
        OutputStream bo = new FileOutputStream(path);
        byte[] bytes = new byte[1024];
        int len  = 0;
        while ((len = bi.read(bytes)) > 0){
            bo.write(bytes,0,len);
        }
        bi.close();
        bo.close();

    }
}
